import { ref } from 'vue'
import router from '@/router/index.ts'
// 定义变量
const dynamicNavigation = ref(4)
let user = null
if (window.localStorage.getItem('user')) {
  user = JSON.parse(window.localStorage.getItem('user')).data
}
// 分享函数
export default function headersFunctionAll () {
  function dynamicSwitch () {
    dynamicNavigation.value = 1
  }
  function recommendedSwitch () {
    dynamicNavigation.value = 2
  }
  function blogSwitch () {
    dynamicNavigation.value = 3
  }
  function myhomeSwitch () {
    dynamicNavigation.value = 4
  }
  function open () {
    this.$confirm('是否确认退出登录', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    }).then(() => {
      this.$message({
        type: 'success',
        message: '已退出登录!'
      })
      window.localStorage.removeItem('user')
      router.push('/login')
    }).catch(() => {
      this.$message({
        type: 'info',
        message: '已取消退出登录'
      })
    })
  }
  return {
    dynamicSwitch,
    dynamicNavigation,
    recommendedSwitch,
    blogSwitch,
    myhomeSwitch,
    open,
    user
  }
}
